package com.mt.roll.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mt.roll.core.api.Assert;
import com.mt.roll.core.base.BaseService;
import com.mt.roll.core.dal.entity.WorkOrderExecute;
import com.mt.roll.core.dal.service.WorkOrderExecuteServiceBiz;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.WorkOrderExecuteQueryParam;
import com.mt.roll.wms.service.WorkOrderExecuteService;
import com.mt.roll.wms.vo.WorkOrderExecuteVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author weihongyang
 * @Date 2021/10/29 3:07 下午
 * @Version 1.0
 */
@Service
@Transactional
public class WorkOrderExecuteServiceImpl extends BaseService implements WorkOrderExecuteService {

    @Autowired
    private WorkOrderExecuteServiceBiz workOrderExecuteServiceBiz;

    @Override
    public R<PageVo<WorkOrderExecute>> page(WorkOrderExecuteQueryParam workOrderExecuteQueryParam) {
        QueryWrapper<WorkOrderExecute> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(workOrderExecuteQueryParam.getName()), WorkOrderExecute.NAME, workOrderExecuteQueryParam.getName())
                .orderByDesc(WorkOrderExecute.ID);
        IPage<WorkOrderExecute> page = workOrderExecuteServiceBiz.page(new Page<>(workOrderExecuteQueryParam.getCurrent(), workOrderExecuteQueryParam.getSize()), wrapper);
        return successful(new PageVo<>(page, WorkOrderExecute.class));
    }

    @Override
    public R<WorkOrderExecute> get(IdParam idParam) {
        WorkOrderExecute workOrderExecute = workOrderExecuteServiceBiz.getById(idParam.getId());
        Assert.notNull("工单执行不存在", workOrderExecute);
        WorkOrderExecuteVo workOrderExecuteVo = WorkOrderExecuteVo.builder().build();
        BeanUtils.copyProperties(workOrderExecute, workOrderExecuteVo);
        return successful(workOrderExecute);
    }
}
